<?php


namespace App\Models\CacheModel;

use App\Models\Api\BaseCache;
use AstroTool\Cache\CacheManage;

class ZlFeedbackHotQuestion extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zl_feedback_hot_question';
    protected $cacheModel = 'feedback.hot_question';

    /**
     * 获取热门问题
     * @return array|mixed
     * @throws \Exception
     */
    public function getQuestionList()
    {
        return $this->getListPage(0);
    }

    /**
     * 批量获取数据
     * @param $ids
     * @param $type
     * @param $sortType
     * @return array|false|string|void
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        if ($ids)
        {
            $where = ['id' => ['in', $ids]];
        } else
        {
            $where = ['status' => 1];
        }
        try
        {
            $data = $this->where($where)->order('id', 'desc')->column('sort,title', 'id');
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        return $data;
    }

    /**
     * 获取热门反馈问题详情
     * @param $id
     * @return array|bool|mixed|string
     * @throws \Exception
     */
    public function getQuestionDetail($id)
    {
        return CacheManage::getInstance()->setCacheConfig('feedback.hot_question_detail', $id)->getDataAndSet(function () use ($id)
        {
            try
            {
                $data = $this->where(['id' => $id])->field('title,content')->findOrFail()->toArray();
            }
            catch (\Exception $e)
            {
                $data = [];
            }
            return $data;
        });
    }
}
